package com.hnchances.studentscoresystem.service.impl;

import com.hnchances.studentscoresystem.entity.Student;
import com.hnchances.studentscoresystem.mapper.StudentMapper;
import com.hnchances.studentscoresystem.service.StudentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 学生管理 Service 实现类
 */
@Service
public class StudentServiceImpl extends BaseServiceImpl<Student, Long, StudentMapper> implements StudentService {

    @Override
    public boolean insert(Student student) {
        // 补全默认值：状态默认为 0（正常）
        if (student.getStatus() == null) {
            student.setStatus(0);
        }
        return mapper.insert(student) > 0;
    }

    @Override
    public Student selectById(Long id) {
        return mapper.selectById(id);
    }

    @Override
    public List<Student> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public boolean update(Student student) {
        return mapper.update(student) > 0;
    }

    @Override
    public boolean deleteById(Long id) {
        return mapper.deleteById(id) > 0;
    }

    @Override
    public Student selectByIdcard(String idcard) {
        return mapper.selectByIdcard(idcard);
    }

    @Override
    public List<Student> selectByClassId(Integer classId) {
        // 实际项目中可在 Mapper 扩展 selectByClassId 方法，此处简化处理
        List<Student> allStudents = mapper.selectAll();
        return allStudents.stream()
                .filter(student -> classId.equals(student.getClassID()))
                .toList();
    }
}